/*******************************************************************************
*  Project      : Minigate Golfin                                 
*  Program ID   : pop_my_out.js
*  Description  : 탈퇴확인 
*
********************************************************************************
*  Program History                                                            
*  Date        Author    Description                                          
*  ----------  --------  -------------------------------------------------------- 
*  2012-05-14  김효순    Created.  
*  2012-05-14  김효순    Complete.  
*******************************************************************************/

jQuery(function($){
	// 메시지
	function clsNote()
	{
		this._HTMLDom = null;
		this.infoData = null;
		
		this._init();
	}
	
	clsNote.prototype = {
		_init: function(){
			var $layer = $("div.pw_area02");
			this._HTMLDom = {
				"$layer": $layer
			}
			
			this.setInfo({});
		}
		, setInfo: function(thisData){
			this.infoData = thisData;
			this.display();
		}
		, display: function(){
			var $layer = this._HTMLDom["$layer"];
			
			$layer.find("span.reserve:first").empty();
			if(this.infoData["갯수"]) $layer.find("span.reserve:first").html(this.infoData["갯수"] + " ");
			
			document.objUtil.setWindowSize();
		}
	}
	
	function clsComm()
	{
		// 예약정보
		this.reserveInfo = null;
		
		this._init();
	}
	
	clsComm.prototype = {
		_init: function(){
			this.reserveInfo = {
				"갯수": null
			}
		}
		, getReserveInfo: function(arr){
			var thisClass = this;
			
			// ajax
			setTimeout(function(){
				var rnd = document.objUtil.random(0, 2);
				thisClass.reserveInfo = {
					"갯수": rnd
				}
				
				document.objControl.finishReserveInfo();
			}, 1000);
		}
		, getReserveData: function(){
			return this.reserveInfo;
		}
	}
	
	
	// 컨트롤
	function clsControl()
	{
		this.objComm = null;
		this.objNote = null;
		
		this._init();
	}
	
	clsControl.prototype = {
		_init: function(){
			if(!opener) self.close();
			if(!opener.document.objControl) self.close();
			
			this.objComm = new clsComm();
			this.objNote = new clsNote();
			
			this._bind();
			
			// 예약정보 받아오기
			document.objGlobal.spinStart("receiving...");
			this.objComm.getReserveInfo();
		}
		, _bind: function(){
			var thisClass = this;
			
			$("img[alt='예약취소 및 탈퇴']").parent("a").click(function(event){
				event.preventDefault();
				
				var thisData = thisClass.objComm.getReserveData();
				
				opener.document.objControl.withdraw(window, thisData["갯수"]);
			});
			
			$("img[alt='아니오']").parent("a").add("img[alt='close']").click(function(event){
				event.preventDefault();
				
				self.close();
			});
		}
		, finishReserveInfo: function(){
			var thisData = this.objComm.getReserveData();
			
			document.objGlobal.spinEnd();
			if(thisData["갯수"]){
				this.objNote.setInfo(thisData);
			}else{
				opener.document.objControl.withdraw(window);
			}
		}
	}
	
	document.objControl = new clsControl();
});